import { _decorator, Component, Label, Node, tween, Vec3 } from 'cc';
import { EventDispatcher } from './EventDispatcher';
const { ccclass, property } = _decorator;

@ccclass('Tips')
export class Tips extends Component {
    @property(Label)
    message: Label = null;
    start() {
        this.node.setPosition(0, -1000);
        EventDispatcher.getInstTarget().on(EventDispatcher.SHOW_TIPS, this.showTips, this)
    }

    protected onDestroy(): void {
        EventDispatcher.getInstTarget().off(EventDispatcher.SHOW_TIPS, this.showTips, this)
    }

    showTips(msg: string) {
        this.message.string = msg;
        this.node.setPosition(0, -100);
        tween(this.node).to(0.5, {
            position: new Vec3(0, 0, 0)
        }).to(0.2, {
            position: new Vec3(0, 1000, 0)
        }).call(() => {
            this.node.setPosition(0, -1000);
        }).start();
    }
}


